/*
 * nlsync
 * Copyright (c) 2010 apechurin 
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
using System;
using System.Collections.Generic;
using System.Text;

#if OLDXLS
using nlsync.XlsOld;
#else
using nlsync.Xls;
#endif

namespace nlsync
{
    /// <summary>
    /// The interface of a strings catalog. All strings are grouped in bundles
    /// (see IStringBundle). There are two implementations of the interface:
    /// - XlsStringCatalog. For each culture all strings of all bundles are 
    ///     stored in a single Xls file;
    /// - ResxStringCatalog. For each culture all strings for each bundle are
    ///     stored in a single Resx file.
    /// </summary>
    public interface IStringCatalog
    {

        /// <summary>
        /// Gets all bundle names.
        /// </summary>
        IEnumerable<String> BundleNames
        {
            get;
        }
        
        /// <summary>
        /// Gets a bundle with the specified name.
        /// </summary>
        /// <param name="name">The bundle name.</param>
        /// <returns>The bundle instance.</returns>
        IStringBundle GetBundle(string name);

        /// <summary>
        /// Closes the catalog and frees all used resources.
        /// It must be last method called.
        /// </summary>
        void Close();
    }

    /// <summary>
    /// Creates an instance of the IStringCatalog interface by its type.
    /// </summary>
    public class StringCatalogFactory
    {
        /// <summary>
        /// Creates a catalog.
        /// </summary>
        /// <param name="type">The catalog type. `xls' and `resx' are 
        ///     supported.</param>
        /// <param name="source">The source string. It's the catalog specific.</param>
        /// <param name="settings">The settings.</param>
        /// <returns>The catalog or null if bad type.</returns>
        public static IStringCatalog Create(string type, string source, 
            ISettings settings)
        {
            if (type == "xls")
                return new XlsStringCatalog(source, settings);
            if (type == "resx")
                return new Resx.ResxStringCatalog(source, settings);

            return null;
        }
    }
}
